package com.haocang.filedemo.config.netty;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class NettyServerInitConfig implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (event.getApplicationContext().getParent() == null) {
            // 开始启动netty 服务器
            log.info("开始启动netty 服务器");
            NettyServer instance = NettyServer.getInstance();
            instance.start();
            log.info("成功启动netty 服务器");
        }
    }
}
